package gameClass;
import java.awt.Rectangle;

/**
 * @author Ben Elliott
 */
public class FrameAnimation {
	
	private Rectangle rectInitialFrame;
	
	public int FrameCount = 1;
	public int CurrentFrame = 0;
	public int PlayCount = 0;
	public float FrameLength = 0.2f;
	public float FrameTimer = 0.0f;
    public String NextAnimation = null;
    
	public FrameAnimation(Rectangle FirstFrame, int Frames)
    {
        rectInitialFrame = FirstFrame;
        FrameCount = Frames;
    }

    public FrameAnimation(int X, int Y, int Width, int Height, int Frames)
    {
        rectInitialFrame = new Rectangle(X, Y, Width, Height);
        FrameCount = Frames;
    }

    public FrameAnimation(int X, int Y, int Width, int Height, int Frames, float frameLength)
    {
        rectInitialFrame = new Rectangle(X, Y, Width, Height);
        FrameCount = Frames;
        FrameLength = frameLength;
    }

    public FrameAnimation(int X, int Y,
        int Width, int Height, int Frames,
        float frameLength, String strNextAnimation)
    {
        rectInitialFrame = new Rectangle(X, Y, Width, Height);
        FrameCount = Frames;
        FrameLength = frameLength;
        NextAnimation = strNextAnimation;
    }
	
	public Rectangle getRectangle(){
		return new Rectangle(
                rectInitialFrame.x + (rectInitialFrame.width * CurrentFrame),
                rectInitialFrame.y, rectInitialFrame.width, rectInitialFrame.height);
	}
	
	public void Update(float elapsed)
    {
        FrameTimer += elapsed;

        if (FrameTimer > FrameLength)
        {
            FrameTimer = 0.0f;
            CurrentFrame = (CurrentFrame + 1) % FrameCount;
            if (CurrentFrame == 0)
                PlayCount = (int)Math.min(PlayCount + 1, Integer.MAX_VALUE);
        }
    }
}
